package bandi.osgi.dalservice.service.devicetypes.impl;

import java.util.List;

import bandi.osgi.dal.dao.beans.Device;
import bandi.osgi.dal.dao.beans.DeviceType;
import bandi.osgi.dal.dao.devices.DeviceDAO;
import bandi.osgi.dal.dao.devicetypes.DeviceTypeDAO;
import bandi.osgi.dalservice.service.devicetypes.DeviceTypeService;

public class DeviceTypeServiceImpl implements DeviceTypeService {
	
	private DeviceTypeDAO dtd;
	private DeviceDAO dd;
	
	

	public DeviceTypeServiceImpl(DeviceTypeDAO dtd, DeviceDAO dd) {
		super();
		this.dtd = dtd;
		this.dd = dd;
	}

	@Override
	public void deleteDeviceType(DeviceType deviceType) {
		List<Device> list = dd.getDevices(deviceType);
		try{
			if(list.size()>0)
				throw new Exception("There are instances of this DeviceType in the database!");
			dtd.deleteDeviceType(deviceType);
		} catch (Exception e) {
			System.err.println("Cannot delete device type. Message: "+e.getMessage());
		}
	}

	@Override
	public DeviceType getDeviceType(long deviceTypeID) {
		return dtd.getDeviceType(deviceTypeID);
	}

	@Override
	public List<DeviceType> getDeviceTypes() {
		return dtd.getDeviceTypes();
	}

	@Override
	public List<DeviceType> getDeviceTypes(String manufacturer) {
		return dtd.getDeviceTypes(manufacturer);
	}

	@Override
	public void insertDeviceType(DeviceType deviceType) {
		dtd.insertDeviceType(deviceType);
	}

	@Override
	public void updateDeviceType(DeviceType deviceType) {
		dtd.updateDeviceType(deviceType);
	}

}
